package com.xinfu.newproject.ui.carFee;


import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.gson.Gson;
import com.parkingwang.vehiclekeyboard.KeyboardInputController;
import com.parkingwang.vehiclekeyboard.PopupKeyboard;
import com.parkingwang.vehiclekeyboard.core.KeyboardEntry;
import com.parkingwang.vehiclekeyboard.core.KeyboardType;
import com.parkingwang.vehiclekeyboard.view.InputView;
import com.parkingwang.vehiclekeyboard.view.KeyboardCallback;
import com.xinfu.newproject.R;
import com.xinfu.newproject.activity.ParkingActivity;
import com.xinfu.newproject.base.BaseFragment;
import com.xinfu.newproject.bean.park_bean.bean.AddMonthCarBean;
import com.xinfu.newproject.bean.park_bean.bean.CheckMonthParkBean;
import com.xinfu.newproject.bean.park_bean.bean.FeeListBean;
import com.xinfu.newproject.bean.park_bean.bean.GetMonthCarListBean;
import com.xinfu.newproject.bean.park_bean.bean.GetParkingBean;
import com.xinfu.newproject.bean.park_bean.bean.PaymentsBean;
import com.xinfu.newproject.bean.paycost.bean.ComputeParkingBean;
import com.xinfu.newproject.interface_.SwichFragmentInterface;
import com.xinfu.newproject.presenter.ParkingPresenter;
import com.xinfu.newproject.util.BToast;
import com.xinfu.newproject.view.IView;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.disposables.Disposable;


/**
 * 临停
 */
public class TemporaryStopFragment extends BaseFragment implements IView.IParkingView {

    @BindView(R.id.layout_next_step_tv)
    TextView nextStepTv;

    @BindView(R.id.fragment_temporary_card_carNum_input_view)
    InputView inputView;

    @BindView(R.id.fragment_temporary_card_carNum_type)
    Button newTypeBtn;

    private PopupKeyboard mPopupKeyboard;

    private SwichFragmentInterface swichFragmentInterface;

    private ParkingPresenter parkingPresenter = new ParkingPresenter(this);

    @Override
    protected int setLayoutResourceID() {
        return R.layout.fragment_temporary_card;
    }

    @Override
    protected void setUpView() {
        nextStepTv.setText("查询");

        // 创建弹出键盘
        mPopupKeyboard = new com.parkingwang.vehiclekeyboard.support.PopupKeyboard(getMContext());
        // 弹出键盘内部包含一个KeyboardView，在此绑定输入两者关联。
        mPopupKeyboard.attach(inputView, getActivity());
        mPopupKeyboard.getKeyboardView()
                .setKeyboardType(KeyboardType.CIVIL_WJ);

        // KeyboardInputController提供一个默认实现的新能源车牌锁定按钮
        mPopupKeyboard.getController()
                .setDebugEnabled(true)
                .bindLockTypeProxy(new KeyboardInputController.ButtonProxyImpl(newTypeBtn) {
                    @Override
                    public void onNumberTypeChanged(boolean isNewEnergyType) {
                        super.onNumberTypeChanged(isNewEnergyType);
                        if (isNewEnergyType) {
                            newTypeBtn.setText("切换为普通车");
                            newTypeBtn.setTextColor(getResources().getColor(R.color.yellow_ff));
                        } else {
                            newTypeBtn.setText("切换为新能源");
                            newTypeBtn.setTextColor(getResources().getColor(R.color.yellow_ff));
                        }
                    }
                });
        mPopupKeyboard.getKeyboardView().addKeyboardCallback(new KeyboardCallback() {
            @Override
            public void onTextKey(String text) {

            }

            @Override
            public void onDeleteKey() {

            }

            @Override
            public void onConfirmKey() {
                mPopupKeyboard.dismiss(getActivity());
            }

            @Override
            public void onUpdateKeyboard(KeyboardEntry keyboard) {

            }
        });
    }

    @Override
    protected void setUpData() {

    }

    @OnClick({R.id.layout_next_step_tv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.layout_next_step_tv:

                if (inputView.getNumber().length() < 7) {
                    BToast.showText(getMContext(), "请输入完整的车牌号");
                } else {
                    if (newTypeBtn.getText().toString().equals("切换为普通车") && inputView.getNumber().length() < 8) {
                        BToast.showText(getMContext(), "请输入完整的车牌号");
                        break;
                    }
                    parkingPresenter.computeParkingCar();
                }


                break;
        }
    }

    @Override
    public String header() {
        return null;
    }

    @Override
    public String userId() {
        return null;
    }

    @Override
    public String parkInfoId() {
        return null;
    }

    @Override
    public String carId() {
        return null;
    }

    @Override
    public Integer carType() {
        return null;
    }

    @Override
    public String projectId() {
        return null;
    }

    @Override
    public String exclusiveFlag() {
        return null;
    }

    @Override
    public String monthCarType() {
        return null;
    }

    @Override
    public String roomId() {
        return null;
    }

    @Override
    public String owner() {
        return null;
    }

    @Override
    public String mobile() {
        return null;
    }

    @Override
    public String images() {
        return null;
    }

    @Override
    public String remark() {
        return null;
    }

    @Override
    public Integer idType() {
        return null;
    }

    @Override
    public String filed1() {
        return null;
    }

    @Override
    public String id() {
        return null;
    }

    @Override
    public String startTime() {
        return null;
    }

    @Override
    public String orderId() {
        return null;
    }

    @Override
    public String licensePlate() {
        return inputView.getNumber().toUpperCase();
    }

    @Override
    public void showToast(String content) {
        BToast.showText(getMContext(), content);
    }

    @Override
    public void closeDispose(Disposable disposable) {

    }

    @Override
    public void showProgress() {
        ((ParkingActivity) getMContext()).showLoding();
    }

    @Override
    public void hideProgress() {
        ((ParkingActivity) getMContext()).hideLoding();
    }

    @Override
    public void getMsg(GetParkingBean getParkingBean) {

    }

    @Override
    public void getMsg(CheckMonthParkBean checkMonthParkBean) {

    }

    @Override
    public void getMsg(AddMonthCarBean addMonthCarBean) {

    }

    @Override
    public void getMsg(GetMonthCarListBean getMonthCarListBean) {

    }

    @Override
    public void getMsg(PaymentsBean paymentsBean) {

    }

    @Override
    public void getMsg(ComputeParkingBean computeParkingBean) {
        if (computeParkingBean.getResult() != null) {
            if (computeParkingBean.getResult().getPkorder() != null) {
                Bundle bundle = new Bundle();
                bundle.putString("response", new Gson().toJson(computeParkingBean));
                ((ParkingActivity) getMContext()).startIntentActivity(StopPaymentActivity.class, bundle);
            }
        }
    }

    @Override
    public void getMsg(FeeListBean feeListBean) {

    }
}
